package com.example.administrator.managesystem.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;


public class ShareUtil {
    private static String fileName="tag";//共享参数文件名字
    private static String userInfo="userInfo";//共享参数文件名字
    private static SharedPreferences sp;
    public static void saveTag( Context context){
        SharedPreferences sp=context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        editor.putBoolean("tag",true);//存入标签值true
        editor.commit();
    }
    public static void saveUserData( Context context,String userId,String userName,String head_img,String token){
        sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
      //  对数据进行编辑，返回editor对象
         editor.putString("userId", ""+userId);
         editor.putString("userName", ""+userName);
         editor.putString("head_img", ""+head_img);
         editor.putString("token", ""+token);
         editor.commit();//将数据持久化到存储介质中
    }
    public static void saveUserHead( Context context,String head_img){
         sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        //  对数据进行编辑，返回editor对象
        editor.putString("head_img", ""+head_img);
        editor.commit();//将数据持久化到存储介质中
    }

    public static boolean getUserIndex( Context context){
        sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        return sp.getBoolean("index",false);//没取到默认值是false
    }
    public static void saveUserIndex( Context context,boolean index){
        sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        //  对数据进行编辑，返回editor对象
        editor.putBoolean("index",index);//存入标签值true
        editor.commit();//将数据持久化到存储介质中
    }
    public static void saveUserName( Context context,String userName){
        sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();
        //  对数据进行编辑，返回editor对象
        editor.putString("userName", ""+userName);
        editor.commit();//将数据持久化到存储介质中
    }

    public static String getUserId(Context context){
        SharedPreferences sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        return sp.getString("userId",null);//没取到默认值是null
    }
    public static String getUserToken(Context context){
        SharedPreferences sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        return sp.getString("token",null);//没取到默认值是null
    }
    public static String getUserImg(Context context){
        SharedPreferences sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        return sp.getString("head_img",null);//没取到默认值是null
    }

    public static String getUserName(Context context){
        SharedPreferences sp=context.getSharedPreferences(userInfo, Activity.MODE_PRIVATE);
        return sp.getString("userName",null);//没取到默认值是null
    }
    public static boolean getTag(Context context){
        SharedPreferences sp=context.getSharedPreferences(fileName, Activity.MODE_PRIVATE);
        return sp.getBoolean("tag",false);//没取到默认值是false
    }


}